﻿using B.S.Domain.Generateplan;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.GenerateplanBasicApplication
{
    public class DeleteGenerateplanBasicCommandHorter:IRequestHandler<DeleteGenerateplanBasicCommand,APIRequst<int>>
    {
        IBaseRepository<GenerateplanBasic> repository;

        public DeleteGenerateplanBasicCommandHorter(IBaseRepository<GenerateplanBasic> repository)
        {
            this.repository = repository;
        }

        public async Task<APIRequst<int>> Handle(DeleteGenerateplanBasicCommand request, CancellationToken cancellationToken)
        {
            var res = new APIRequst<int>();
            var source = await repository.GetById(request.GenerateplanBasicId);
            if (source == null)
            {

                res.Msg = "没有查找到您所需要的数据";
                return res;
            }
            source.IsDel = true;
            var del = await repository.Update(source);
            if (del > 0)
            {
                res.Msg = "逻辑删除成功";
                res.Data = del;
                return res;
            }
            else
            {

                res.Msg = "逻辑删除失败";
                res.Data = del;
                return res;
            }
        }
    }
}
